import { Component } from 'react';
import { Layout, Card, Breadcrumb, Table, Tag, Space } from 'antd';
import axios from '@/utils/index.js';
class Auther extends Component {
  constructor() {
    super();
    this.state = {

      columns: [
        {
          title: '#',
          key: 'id',
        },
        {
          title: '权限名称',
          dataIndex: 'authName',
          key: 'authName',
        },
        {
          title: '路径',
          dataIndex: 'path',
          key: 'path',
        },
        {
          title: '权限等级',
          key: 'children',
          render: (row) => (
            <Tag>{row.pid===0 ? '一级' : '二级'}</Tag> 
          )
        }
      ],
      data: []
    }
  }
  //初始化数据
  componentDidMount() {
    this.getAuthlist()
  }
  //获取权限列表
  getAuthlist = async () => {
    let result = await axios.get('/rights/tree')
    console.log(result);
    this.setState({
      data: result.data.data
    })
  }
  render() {
    return (
      <Layout>
        <Breadcrumb style={{ margin: '5px 0', marginBottom: "10px" }}>
          <Breadcrumb.Item href="home">主页</Breadcrumb.Item>
          <Breadcrumb.Item href="user">权限</Breadcrumb.Item>
          <Breadcrumb.Item href="/home/user/user">列表</Breadcrumb.Item>
        </Breadcrumb>
        <Card>
          <Table columns={this.state.columns} dataSource={this.state.data} rowKey="id" />
        </Card>
      </Layout>
    );
  }
}
export default Auther;
